home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_08_03 / 8n03052a < prev    next >
Text File  |  1990-03-18  |  928b  |  51 lines

  1. *****Listing 4*****
  2.  
  3.  
  4. // a buffer is a kind of yacht of characters, which can optionally be
  5. // associated with a File
  6. class Buffer : public Yacht {
  7. public:
  8.     Buffer() : () {}  // constructor for buffers not connected to a file
  9.  
  10.     Buffer( char *filename) : ()
  11.     {
  12.         if( filename == 0 )
  13.             ;
  14.         else if( read( filename) )
  15.             ;
  16.         else
  17.             error( "could not open %s\n", filename);
  18.  
  19.         begin();
  20.     }
  21.  
  22.     Truth read( char *filename)
  23.     {
  24.         int r = 1;
  25.         if( filename ) {
  26.             File f( filename);
  27.             if( f.isok() ) {
  28.                 for( ; !f.iseof(); next() )
  29.                     putb( f.get() );
  30.             } else r = 0;
  31.         }
  32.         return r;
  33.     }
  34.  
  35.     Truth write( char *filename)
  36.     {
  37.         int r = 1;
  38.         if( filename ) {
  39.             File f( filename, "w");
  40.             if( f.isok() ) {
  41.                 for( ; !isend(); next() )
  42.                     f.put( geta() );                      
  43.             } else r = 0;
  44.         }
  45.         return r;
  46.     }
  47. private:
  48.     void error( char *msg, char *arg) { printf( msg, arg); }
  49. };
  50.  
  51.